package tv.youxing.android.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import tv.youxing.android.R;
import tv.youxing.android.entity.HomeModel;
import tv.youxing.android.ui.ModuleMoreDetailsActivity;
import tv.youxing.android.utils.PicassoUtils;

import static tv.youxing.android.R.id.imageView;

/**
 * Created by Administrator on 2017/7/24.
 */

public class HomeFragment_Zhuanjifenlei_Adapter extends RecyclerView.Adapter<HomeFragment_Zhuanjifenlei_Adapter.Holder> {


    Context mContext;
    List<HomeModel.ResultBean.AlbumClassifysBean> tablayoutList = new ArrayList<>();


    public HomeFragment_Zhuanjifenlei_Adapter(Context context, List<HomeModel.ResultBean.AlbumClassifysBean> tablayoutList) {
        mContext = context;
        this.tablayoutList = tablayoutList;
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext
        ).inflate(R.layout.layout_item_tab, parent,
                false);//这个布局就是一个imageview用来显示图片


        Holder h = new Holder(view);

        return h;
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {
        PicassoUtils.loadImageView(mContext, tablayoutList.get(position).getCover().toString(), holder.iv);
//        PicassoUtils.loadImageViewSize(mContext, tablayoutList.get(position).getCover().toString(),R.dimen.x15,R.dimen.x15, R.drawable.icon_dufault,holder.iv);
        holder.title.setText(tablayoutList.get(position).getAlbum_classify_name());


        holder.rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, ModuleMoreDetailsActivity.class);
                intent.putExtra("album_classify_id", tablayoutList.get(position).getAlbum_classify_id() + "");
                mContext.startActivity(intent);
            }
        });
    }


    @Override
    public int getItemCount() {
        return tablayoutList.size();
    }


    class Holder extends RecyclerView.ViewHolder {

        LinearLayout rootView;
        ImageView iv;
        TextView title;


        public Holder(View itemView) {
            super(itemView);

            rootView = itemView.findViewById(R.id.rootView);
            iv = itemView.findViewById(imageView);
            title = itemView.findViewById(R.id.textView);
        }
    }
}
